package service;

import java.util.ArrayList;

import helpers.CrawlerOloHelper;
import helpers.OloHepler;

public class RunThread extends Thread {
	public void run() {
		while (true) {
			try {
				int page =  OloHepler.page;
				if (page <= 3168) {
					String strPage = Integer.toString((page - 1) * OloHepler.step + 1);
					String url = "http://www.olo.vn/trang_" + strPage;
					System.out.println(url);
					ArrayList<String> listLink = CrawlerOloHelper.getLink(url);
					try {
						for (int i = 0; i< listLink.size(); i++) { 
							ActiveMQService.sendContentSMS(listLink.get(i));
							System.out.println(listLink.get(i));
						}
					} catch (Exception e) {
						e.printStackTrace();
					}
					
					OloHepler.page = page + 1;
				} else {
					System.out.println("Page limit!");
				}
				
				Thread.currentThread();	
				Thread.sleep(15 * 1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args) {
		new RunThread().start();
	}
}
